package cn.woniu.wxy.handler;

import cn.woniu.wxy.util.ResponseResult;
import com.alibaba.fastjson.JSON;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 用户退出
 */
public class MyLogoutSucesshandler implements LogoutSuccessHandler {
//    @Autowired
//    private RedisTemplate<String,String> redisTemplate;
    @Override
    public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        httpServletRequest.setCharacterEncoding("utf-8");
        httpServletResponse.setCharacterEncoding("utf-8");
        httpServletResponse.setContentType("application/json;charset=utf8");
        PrintWriter writer = httpServletResponse.getWriter();


        String json = JSON.toJSONString(ResponseResult.LOGOUT);
        writer.print(json);
        writer.flush();
        writer.close();
    }
}
